' TAMS 1887 USB Switch Controller Example
' A sample program to control a switch.

Imports VBexamples.tamsSC
Public Class example1
    Sub example1()

        ' Declare the handle to the USB device.
        Dim handle As IntPtr

        ' Start a session with the USB device.  This call will automatically find the USB device.
        ' If there is more than one USB device, then the ID string must be passed to uniquely
        ' identify which USB device session to start.  See example2.

        handle = tamsSCstart("")
        If INVALID_HANDLE_VALUE = handle.ToInt32 Then
            MsgBox(tamsSCerror(), MsgBoxStyle.OKOnly, "Error")
            Exit Sub
        End If

        ' Set switch 4 to position B.  
        ' For example, switch 4 in this case could be an Agilent 1810, 1811, or 1812.
        ' This call will energize one of the switch's two coils, wait until the switching operation
        ' has completed, and then return.

        tamsSCswitch(handle, SWITCH_4, POSITION_B)

        ' Optionally:  with error checking.  This time the switch is put to position A.

        If FAIL = tamsSCswitch(handle, SWITCH_4, POSITION_A) Then
            MsgBox(tamsSCerror(), MsgBoxStyle.OKOnly, "Error")
            Exit Sub
        End If

        ' Shut down the USB session before exiting the program

        tamsSCend(handle)
    End Sub
End Class
